import com.alibaba.fastjson.JSON
import org.codehaus.jackson.map.ObjectMapper

import scala.collection.JavaConversions._
import scala.collection.mutable.ListBuffer

/**
  * @Desc
  * @Author chenchi03
  * @CreateTime 2020-03-06 21:16
  */
object Test3 {
    def main(args: Array[String]): Unit = {
//        val str = "{\"chat_time\":1583901030059,\"account_type\":\"uid\",\"msgs\":[{\"paid\":17592190828063,\"pa_type\":7,\"sub_pa_type\":0,\"pa_class_type\":0,\"msg_category\":\"\",\"business_source\":\"\",\"third_id\":\"\",\"content_type\":9,\"msgid2\":1583892839098336,\"msg_key\":\"1583892795806291\"},{\"paid\":17592190828063,\"pa_type\":7,\"sub_pa_type\":0,\"pa_class_type\":0,\"msg_category\":\"\",\"business_source\":\"\",\"third_id\":\"\",\"content_type\":9,\"msgid\":1583468953640569,\"msg_key\":\"1583468910228184\"},{\"paid\":17592190828063,\"pa_type\":7,\"sub_pa_type\":0,\"pa_class_type\":0,\"msg_category\":\"\",\"business_source\":\"\",\"third_id\":\"\",\"content_type\":9,\"msgid\":1583718592054833,\"msg_key\":\"1583718544807246\"},{\"paid\":17592190828063,\"pa_type\":7,\"sub_pa_type\":0,\"pa_class_type\":0,\"msg_category\":\"\",\"business_source\":\"\",\"third_id\":\"\",\"content_type\":9,\"msgid\":1583203946878905,\"msg_key\":\"1583203882948958\"},{\"paid\":17592190828063,\"pa_type\":7,\"sub_pa_type\":0,\"pa_class_type\":0,\"msg_category\":\"\",\"business_source\":\"\",\"third_id\":\"\",\"content_type\":9,\"msgid\":1583636321982054,\"msg_key\":\"1583636267394451\"},{\"paid\":17592190828063,\"pa_type\":7,\"sub_pa_type\":0,\"pa_class_type\":0,\"msg_category\":\"\",\"business_source\":\"\",\"third_id\":\"\",\"content_type\":9,\"msgid\":1583380224968900,\"msg_key\":\"1583380180882695\"},{\"paid\":17592190828063,\"pa_type\":7,\"sub_pa_type\":0,\"pa_class_type\":0,\"msg_category\":\"\",\"business_source\":\"\",\"third_id\":\"\",\"content_type\":9,\"msgid\":1583800828212576,\"msg_key\":\"1583800779203382\"}]}"
//        val userid = "1234567890"
//
//        val dataNode = new ObjectMapper().readTree(str)
//
//        val msgStr = dataNode.get("msgs").toString
//
//        val msgNode = new ObjectMapper().readTree(msgStr)
//
//        val msgs = msgNode.map(x => if(x.has("msgid")) (x.get("msgid").asText(), userid) else ("", userid)).toList
//
//        msgs.foreach(println)

        test2()
    }

    def test(): Unit ={
        val str = "{\"chat_time\":1583901030059,\"account_type\":\"uid\",\"msgs\":[{\"paid\":17592190828063,\"pa_type\":7,\"sub_pa_type\":0,\"pa_class_type\":0,\"msg_category\":\"\",\"business_source\":\"\",\"third_id\":\"\",\"content_type\":9,\"msgid2\":1583892839098336,\"msg_key\":\"1583892795806291\"},{\"paid\":17592190828063,\"pa_type\":7,\"sub_pa_type\":0,\"pa_class_type\":0,\"msg_category\":\"\",\"business_source\":\"\",\"third_id\":\"\",\"content_type\":9,\"msgid\":1583468953640569,\"msg_key\":\"1583468910228184\"},{\"paid\":17592190828063,\"pa_type\":7,\"sub_pa_type\":0,\"pa_class_type\":0,\"msg_category\":\"\",\"business_source\":\"\",\"third_id\":\"\",\"content_type\":9,\"msgid\":1583718592054833,\"msg_key\":\"1583718544807246\"},{\"paid\":17592190828063,\"pa_type\":7,\"sub_pa_type\":0,\"pa_class_type\":0,\"msg_category\":\"\",\"business_source\":\"\",\"third_id\":\"\",\"content_type\":9,\"msgid\":1583203946878905,\"msg_key\":\"1583203882948958\"},{\"paid\":17592190828063,\"pa_type\":7,\"sub_pa_type\":0,\"pa_class_type\":0,\"msg_category\":\"\",\"business_source\":\"\",\"third_id\":\"\",\"content_type\":9,\"msgid\":1583636321982054,\"msg_key\":\"1583636267394451\"},{\"paid\":17592190828063,\"pa_type\":7,\"sub_pa_type\":0,\"pa_class_type\":0,\"msg_category\":\"\",\"business_source\":\"\",\"third_id\":\"\",\"content_type\":9,\"msgid\":1583380224968900,\"msg_key\":\"1583380180882695\"},{\"paid\":17592190828063,\"pa_type\":7,\"sub_pa_type\":0,\"pa_class_type\":0,\"msg_category\":\"\",\"business_source\":\"\",\"third_id\":\"\",\"content_type\":9,\"msgid\":1583800828212576,\"msg_key\":\"1583800779203382\"}]}"
        val userid = "1234567890"

        val dataNode = JSON.parseObject(str)
        println(dataNode.getInteger("chat2_time"))

        val msgs = dataNode.getJSONArray("msgs")

        val list = ListBuffer[String]()
        for(i <- 0 until msgs.size()) {
            list.append(msgs.getJSONObject(i).getString("msgid"))
        }

        val list2 = list.map(item => (item, userid)).toList
        println(list2)
    }


    def test2(): Unit ={
        val row = "1234567"
        println(row.split("""\],"data":""").mkString(","))
    }
}
